<?php

/**
 * @filename Member_ImportController.php
 * @author qiankun<qiankun@dodoca.com>
 * @datetime 2017/3/30
 * @description 会员导出
 */
class Member_ImportController extends SellerController
{
    protected $userId;
    protected $sellerId;
    protected $shopId;
    protected $role;
    protected $excelMaxLength;
    protected $excelMaxExportLength;

    public function init()
    {
        parent::init();
        $this->excelMaxLength = 2000;//EXCEL允许导入最大值
        $this->excelMaxExportLength = 2000;//EXCEL允许导出最大值
        $this->userId = intval($this->getCurrentUser()->get('id'));
        $this->shopId = intval($this->getCurrentUser()->getShopId());
        $this->sellerId = intval($this->getCurrentUser()->getSellerId());
        $this->role = intval($this->getCurrentUser()->getRole());  //账户类型（1：商户账号；2：超级；3：店长；4：收银员）
    }

    /**
     * @author qiankun
     * @Fuction name indexAction
     * @description 未开卡会员
     */
    public function indexAction()
    {
        //基本条件
        $params = $this->_request->getQuery();
        $page = max(1, intval($params['page']));
        $pageSize = 30;
        $shopId = $this->shopId;

        $sellerId = $this->sellerId;
        $where['seller_id'] = $sellerId;
        $where['shop_id'] = $shopId;
        $where['status'] = 2;//商家后台导入的会员并且还没有主动加入会员的用户
        $memberImportModel = new Statistics_MemberImportModel();
        $memberImportFileModel = new Statistics_MemberImportFileModel();
        $cardList = User_CardService::getListBySellerId($sellerId);
        if(!empty($cardList))
        {
            foreach($cardList as $key => $value)
            {
                $levelList[$value['level']] = $value['card_name'];//获得会员卡等级键值对array('等级'=>'等级名称')
            }
        }

        //筛选条件
        !empty($params['user_name']) && $where['true_name'] = array('LIKE','%'.$params['user_name'].'%');
        !empty($params['user_phone']) && $where['phone'] = array('LIKE','%'.trim($params['user_phone']).'%');
        !empty($params['level']) && $where['level'] = array('eq',intval($params['level']));
        !empty($params['start_time']) && $where['create_time'] = array('gt',strtotime($params['start_time']));
        !empty($params['end_time']) && $where['create_time'] = array('lt',strtotime($params['end_time'])+3600*24);
        if($params['start_time'] && $params['end_time'])
        {
            $where['create_time'] = array('between',strtotime($params['start_time']).",".(strtotime($params['end_time'])+3600*24));
        }
        $list = $memberImportModel->listPage($where, array(), 'id DESC', $page, $pageSize);
        $count = $memberImportModel->count;
        $totalPage = $memberImportModel->totalPage;
        if(!empty($list))
        {
            foreach($list as $key => $value)
            {
                $list[$key]['level_name'] = $levelList[$value['level']];//获得会员等级名称
                $list[$key]['balance'] = number_format($value['balance'],2,".","");
            }
        }
        //获得excel基本数据
        $where = array(
            'status' => 2,
            'seller_id' => $sellerId,
            'shop_id' => $this->shopId
        );
        if($importFile = $memberImportFileModel->find($where,array('id','create_time'),'id DESC'))
        {
            $importFile['create_time'] = date('Y-m-d H:i', $importFile['create_time']);
            $where = array('import_file_id' => $importFile['id'], 'status' => 2);//成功条数
            $successCount = $memberImportModel->count($where);
            $where = array('import_file_id' => $importFile['id'], 'status' => 3);//失败条数
            $errorCount = $memberImportModel->count($where);
        }
        //获得excel基本数据END
        $data = array(
            'count' => $count,
            'params' => $params,
            'totalPage' => $totalPage,
            'page' => $page,
            'member_list' => $list,
            'card_list' => $cardList,
            'successCount' => $successCount,
            'errorCount' => $errorCount,
            'importFile' => $importFile,
        );
        $this->assign('loadModuleScript', true);
        $this->display($data, 'member/import/index.html');
    }

    /**
     * @author qiankun
     * @Fuction name ajaxDeleteMemberAction
     * @description ajax删除会员
     * @throws Exception
     */
    public function ajaxDeleteMemberAction()
    {
        try
        {
            if(!$this->_request->isXmlHttpRequest())
            {
                throw new Exception('非法请求');
            }
            $params = $this->_request->getPost();
            $id = intval($params['id']);
            if(empty($id))
            {
                throw new Exception('无效ID');
            }
            $memberImportModel = new Statistics_MemberImportModel();
            $where = array(
                'id' => $id,
                'shop_id' => $this->shopId,
                'seller_id' => $this->sellerId,
            );
            if($importMember = $memberImportModel->find($where))
            {
                if($importMember['status'] == 4)
                {
                    throw new Exception('无法删除已绑定的会员');
                }
                if($memberImportModel->deleteData($where))
                {
                    $this->ajaxReturn(
                        array(
                            'code' => '1', 'msg' => "删除成功"
                        )
                    );
                }
                else
                {
                    throw new Exception('删除失败');
                }
            }
            else
            {
                throw new Exception('无效ID');
            }
        }
        catch (Exception $e)
        {
            $this->ajaxReturn(array('code'=>0,'msg'=>$e->getMessage()));
        }

    }

    /**
     * @author qiankun
     * @Fuction name ajaxMemberImportAction
     * @description 批量导入Excel数据
     * @throws Exception
     */
    public function ajaxMemberImportAction()
    {
        try
        {
            if(!$this->_request->isXmlHttpRequest())
            {
                throw new Exception('非法请求');
            }
            $params = $this->_request->getPost();

            $memberImportFileModel = new Statistics_MemberImportFileModel();
            $memberImportModel = new Statistics_MemberImportModel();
            Tool_Log::info('导入文件-1', 'ajaxMemberImport', array('result' => $params));
            //检验EXCEL是否有数据未检测完成
            $where = array(
                'shop_id' => $this->shopId,
                'seller_id' => $this->sellerId,
                'status' => 1
            );

            if($memberImportFileModel->find($where,array('id')))
            {
                throw new Exception("您之前的导入任务正在进行中，请等待导入完成后继续操作，谢谢！完成后可在导入操作页查看具体的反馈信息（只显示最近一次的导入反馈）；若有失败情况，可下载对应Excel表格查看具体内容。",'10003');
            }

            //获得导入信息
            $picDataModel = new PicDataModel();
            if(!$fileInfo = $picDataModel->getInfoById(intval($params['file_id'])))
            {
                throw new Exception("无效的文件ID",'10004');
            }
            //解析excel开始
            $fileType = $fileInfo['file_ext'];
            $targetFile = $fileInfo['org'];
            if(empty($targetFile))
            {
                throw new Exception("找不到文件或者权限不够",'10005');
            }
            Tool_Log::info('导入文件-2', 'ajaxMemberImport', array('result' => $fileInfo,'fileType'=>$fileType));
            $targetFile = $this->grabFile($targetFile,'',$_SERVER["SINASRV_DATA_TMP"]);//移动文件到临时文件夹下
            Tool_Log::info('导入文件-3', 'ajaxMemberImport', array('result' => $fileInfo,'fileType'=>$fileType));
            if($fileType == "xls")
            {
                $objReader = PHPExcel_IOFactory::createReader('Excel5');
            }
            else
            {
                //throw new Exception("导入数据失败，目前只支持xls格式文件",'10008');
                $objReader = PHPExcel_IOFactory::createReader('Excel2007');
            }

            $excelFileExtension = array('xls', 'xlsx', 'XLS', 'XLSX'); //允许的文件后缀

            $allData = array();
            //验证文件类型
            if(in_array($fileType, $excelFileExtension))
            {
                //获取EXCEL文件中的数据
                require_once __SYSDIR__ . '/include/lib/PHPExcel.php';
                Tool_Log::info('导入文件-4', 'ajaxMemberImport', array('result' => $fileInfo,'fileType'=>$fileType));
                $objPHPExcel = $objReader->load($targetFile);
                Tool_Log::info('导入文件-5', 'ajaxMemberImport', array('result' => $fileInfo,'fileType'=>$fileType));
                $sheet = $objPHPExcel->getSheet(0);
                $rows = $sheet->getHighestRow();                        // 取得总行数
                $columns = $sheet->getHighestColumn();                  // 取得总列数
                $countSuccess = 0;                                      //成功导入的数据的数量
                if($rows > $this->excelMaxLength)//行数超过规定值
                {
                    throw new Exception("excel数据不得超过".$this->excelMaxLength."行,您的数据有".($rows-1)."行",'10004');
                }
                //插入member_import_file表
                $data = array(
                    'file_src' => $fileInfo['org'],
                    'shop_id' => $this->shopId,
                    'seller_id' => $this->sellerId,
                    'user_id' => $this->userId,
                    'create_time' => SYS_TIME,
                    'status' => 1,
                    'is_del' => 0,
                    'file_id' => intval($params['file_id'])
                );
                $insertId = $memberImportFileModel->insertData($data);
                if(!$insertId)
                {
                    throw new Exception("导入数据失败",'10004');
                }
                for($i = 1; $i <= $rows+1; $i++)
                {
                    $cell_values = array();
                    for($j = 'A'; $j <= $columns; $j++)
                    {
                        $address = $j . $i;// 单元格坐标
                        $encode = mb_detect_encoding(
                            $sheet->getCell($address)->getValue(), array("ASCII", "UTF-8", "GB2312", "GBK", "BIG5")
                        );//获取原有编码
                        $cell_values[] = iconv($encode, 'utf-8', $sheet->getCell($address)->getValue());//读取单元格信息
                    }
                    Tool_Log::info('导入文件-6', 'ajaxMemberImport', array('result' => $cell_values,'fileType'=>$fileType));
                    //var_dump($cell_values[0].':'.$cell_values[5].':'.substr_count($cell_values[5],'/'));
                    //验证是否是模板
                    if($i == 1)
                    {
                        if($cell_values[0] != '手机号(不可重复)' || $cell_values[1] != '会员卡等级' || $cell_values[2] != '余额' || $cell_values[3] != '姓名' || $cell_values[4] != '性别' || $cell_values[5] != '生日')
                        {
                            $memberImportFileModel->deleteData(array('id' => $insertId));
                            throw new Exception("导入数据失败，请检查文件是否符合要求，请下载模板填写",'10007');
                        }else{
                            continue;
                        }
                    }
                    // 手机号和等级都不则跳过本条信息
                    if(empty($cell_values[0]) && empty($cell_values[1]))
                    {
                        continue;
                    }
                    //处理日期时间
                    if(strlen($cell_values[5]) > 6 )
                    {
                        $cell_values[5] = 0;
                    }

                    //过滤非法字符
                    foreach($cell_values as $key => $value)
                    {
                        if($value)
                        {
                            $cell_values[$key] = $this->strFilter($value);
                        }
                    }
                    //金额格式错误，设为0
                    if(!is_numeric($cell_values[2]) || $cell_values[2] < 0 || strlen($cell_values[2]) > 15)
                    {
                        $cell_values[2] = 0;
                    }
                    //处理日期时间;
                    if($cell_values[5]> 0 && strlen($cell_values[5]) < 11 && substr_count($cell_values[5],'/') == 0)
                    {
                        $birthday = strtotime(gmdate("Y-m-d H:i:s", PHPExcel_Shared_Date::ExcelToPHP($cell_values[5])));//处理excel的时间

                        if($birthday > SYS_TIME )
                        {
                            $birthday = 0;
                        }
                    }
                    else
                    {
                        $birthday = 0;
                    }
                    //验证会员等级
                    if(!Tool_Validator::isNonNegative($cell_values[1]) ||  strlen($cell_values[1]) > 11 || ceil($cell_values[1]) != $cell_values[1] )
                    {
                        $cell_values[1] = 0;
                    }
                    //验证姓名长度
                    if(strlen($cell_values[3]) > 49)
                    {
                        $cell_values[3] = '';
                    }
                    //验证卡号长度
                    if(strlen($cell_values[6]) > 19)
                    {
                        $cell_values[6] = '';
                    }
                    $data = array(
                        'seller_id' => $this->sellerId,
                        'shop_id' => $this->shopId,
                        'status' => 1,
                        'phone' => strlen($cell_values[0])>19 ? '' : $cell_values[0],
                        'level' => $cell_values[1],
                        'balance' => $cell_values[2],
                        'true_name' => $cell_values[3],
                        'sex' => $cell_values[4] == '男' ? 1 : ($cell_values[4] == '女' ? 2 : 0),
                        'birthday' => $birthday,
                        'card_no' => $cell_values['6'],
                        'create_time' => SYS_TIME,
                        'import_file_id' => $insertId
                    );
                    if($data['phone'] || $data['level'])
                    {
                        $allData[] = $data;
                        $countSuccess++;
                    }
                }
                //var_dump($data);exit();
                if($memberImportModel->insertAll($allData))//一次性保存到表
                {
                    $where = array('id' => $insertId);
                    $data = array('status' => 1);
                    $memberImportFileModel->updateData($data,$where);//更新member_import_file表
                    $this->ajaxReturn(
                        array(
                            'code' => '10000', 'msg' => "成功导入" . $countSuccess . "条数据,等待系统验证合格性"
                        )
                    );
                }
                else
                {
                    throw new Exception("导入数据失败，请检查文件是否符合要求",'10003');
                }
            }
            else
            {
                throw new Exception("EXCEL格式不正确",'10003');
            }
        }
        catch(Exception $e)
        {
            $this->ajaxReturn(
                array(
                    'code' => $e->getCode(),
                    'msg'  => $e->getMessage()
                )
            );
        }
    }

    /**
     * @author qiankun
     * @Fuction name addAction
     * @description 会员单个添加
     */
    public  function addAction()
    {
        $data = array();
        //会员卡等级
        $memberCardModel = new U_CardAttrModel();
        $where = array(
            'seller_id' => $this->sellerId,
            'status' => 1,
        );
        $levelAll =  $memberCardModel->select($where,array('id','level','card_name'));
        $data['levelAll'] = $levelAll;
        $data['nowTime'] = SYS_TIME;
        $this->assign('loadModuleScript', true);
        $this->display($data, 'member/import/add.html');
    }

    /**
     * @author qiankun
     * @Fuction name ajaxAddSaveAction
     * @description 保存添加会员
     */
    public function ajaxAddSaveAction()
    {
        //基本条件
        try
        {
            if(!$this->_request->isXmlHttpRequest())
            {
                throw new Exception('非法请求');
            }
            Tool_Log::info('1', 'ajax-add-save', array('method' => '1', 'msg' => '1', 'result' => '11'));
            $params = $this->_request->getPost();
            if(!$params['balance']){
                $params['balance'] = 0;
            }
            else
            {
                $params['balance'] = number_format($params['balance'], 2, ".", "");
            }
            if(!in_array($params['sex'], array(0, 1, 2)))
            {
                $params['sex'] = 0;
            }

            Tool_Log::info('params', 'ajax-add-save', array('method' => 'params', 'msg' => 'params', 'result' => $params));
            $params['birthday'] = $params['birthday'] ? strtotime($params['birthday']) : 0;
            $params['seller_id'] = $this->sellerId;
            $params['shop_id'] = $this->shopId;
            Tool_Log::info('params', 'ajax-add-save', array('method' => 'params', 'msg' => '更新结果', 'result' => $params));
            $memberImportModel = new Statistics_MemberImportModel();
            if(strlen($params['true_name']) > 49)
            {
                $params['true_name'] = '';
            }
            if(strlen($params['balance']) > 15)
            {
                $params['balance'] = 0;
            }
            if($params['birthday'] > SYS_TIME || strlen($params['birthday']) > 11 || $params['birthday'] < strtotime('1911/01/01'))
            {
                $params['birthday'] = 0;
            }
            //验证会员等级
            if(!Tool_Validator::isNonNegative($params['level']) ||  strlen($params['level']) > 11 || ceil($params['level']) != $params['level'] )
            {
                $params['level'] = 0;
            }
            //检测是否符合要求
            $isValidate = Member_ImportService::checkMemberImport($params);
            Tool_Log::info('插入数据', 'ajax-add-save', array('method' => 'member-import', 'msg' => '更新结果', 'result' => $isValidate));
            if($isValidate['status'] == 0)
            {
                throw new Exception($isValidate['msg'], -1);
            }

            $data = array(
                'seller_id' => $this->sellerId,
                'shop_id' => $this->shopId,
                'status' => 2,
                'phone' => $params['phone'],
                'level' => $params['level'],
                'true_name' => $params['true_name'],
                'sex' => intval($params['sex']),
                'birthday' => $params['birthday'] ? $params['birthday'] : 0,
                'balance' => $params['balance'],
                'create_time' => SYS_TIME,
                'type' => 2
            );
            Tool_Log::info('插入数据', 'ajax-add-save', array('method' => 'member-import', 'msg' => '更新结果', 'result' => $data));
            if($memberImportModel->insertData($data) === false)
            {
                throw new Exception('保存失败', -1);
            }
            else
            {
                $this->ajaxReturn(
                    array('code' => 10000, 'msg' => '导入会员成功，状态为未开卡')
                );
            }
        }
        catch (Exception $e)
        {
            $this->ajaxReturn(array('code'=>'-1','msg'=>$e->getMessage()));
        }
    }

    /**
     * @author qiankun
     * @Fuction name ajaxCheckMemberAction
     * @description  异步验证数据返回错误消息
     */
    public function ajaxCheckMemberAction()
    {
        //基本条件

        $params = $this->_request->getPost();
        if($params['phone'])
        {
            //手机号做唯一性验证
            $userFans = new U_FansModel($this->sellerId);
            $where = array(
                'seller_id' => intval($params['seller_id']), 'phone' => $params['phone']
            );
            if($userFans->count($where))
            {
                $type = 'false';
                exit($type);
            }

            //验证导入合格数据中是否含有重复手机号
            $where = array(
                'seller_id' => $this->sellerId,
                'shop_id' =>  $this->shopId,
                'status' => array('in', '2,4'),
                'phone' => $params['phone']
            );
            $memberImportModel = new Statistics_MemberImportModel();
            if($memberImportModel->count($where))
            {
                $type = 'false';
            }
            else
            {
                $type = 'true';
            }
            exit($type);
        }
        //验证会员等级
        if($params['level'])
        {
            $memberCard = new U_CardAttrModel();
            $where = array(
                'seller_id' => intval($params['seller_id']), 'level' => intval($params['level']), 'status' => 1
            );
            if(!$hasLevel = $memberCard->find($where, array('id', 'status')))
            {
                $type = 'false';
            }
            else
            {
                $type = 'true';
            }
            exit($type);
        }
        else
        {
            $type = 'false';
            exit($type);
        }
    }
    /**
     * @author qiankun
     * @Fuction name grabFile
     * @description 抓取文件
     * @param string $url
     * @param string $filename
     * @param string $file
     * @return bool|string
     */
    private function grabFile($url = '', $filename = '',$file = 'excel')
    {
        if($url == '') {
            return false; //如果 $url 为空则返回 false;
        }

        $extName = strrchr($url, '.'); //获取文件的扩展名
        if($filename == '') {
            $filename = SYS_TIME.rand(0,10000).$extName; //以时间戳另起名
        }
        //开始捕获
        ob_start();
        readfile($url);
        $imgData = ob_get_contents();
        ob_end_clean();
        //$size = strlen($imgData);
        $localFile = fopen($file.'/'.$filename , 'a');
        fwrite($localFile, $imgData);
        fclose($localFile);
        return $file.'/'.$filename;
    }

    /**
     * @author qiankun
     * @Fuction name strFilter
     * @description 过滤非法字符
     * @param $str
     * @return string
     */
    private function strFilter($str){
        $str = str_replace('`', '', $str);
        $str = str_replace('·', '', $str);
        $str = str_replace('~', '', $str);
        $str = str_replace('!', '', $str);
        $str = str_replace('！', '', $str);
        $str = str_replace('@', '', $str);
        $str = str_replace('#', '', $str);
        $str = str_replace('$', '', $str);
        $str = str_replace('￥', '', $str);
        $str = str_replace('%', '', $str);
        $str = str_replace('^', '', $str);
        $str = str_replace('……', '', $str);
        $str = str_replace('&', '', $str);
        $str = str_replace('*', '', $str);
        $str = str_replace('(', '', $str);
        $str = str_replace(')', '', $str);
        $str = str_replace('（', '', $str);
        $str = str_replace('）', '', $str);
        $str = str_replace('_', '', $str);
        $str = str_replace('——', '', $str);
        $str = str_replace('+', '', $str);
        $str = str_replace('=', '', $str);
        $str = str_replace('|', '', $str);
        $str = str_replace('\\', '', $str);
        $str = str_replace('[', '', $str);
        $str = str_replace(']', '', $str);
        $str = str_replace('【', '', $str);
        $str = str_replace('】', '', $str);
        $str = str_replace('{', '', $str);
        $str = str_replace('}', '', $str);
        $str = str_replace(';', '', $str);
        $str = str_replace('；', '', $str);
        $str = str_replace(':', '', $str);
        $str = str_replace('：', '', $str);
        $str = str_replace('\'', '', $str);
        $str = str_replace('"', '', $str);
        $str = str_replace('“', '', $str);
        $str = str_replace('”', '', $str);
        $str = str_replace(',', '', $str);
        $str = str_replace('，', '', $str);
        $str = str_replace('<', '', $str);
        $str = str_replace('>', '', $str);
        $str = str_replace('《', '', $str);
        $str = str_replace('》', '', $str);
        $str = str_replace('。', '', $str);
        $str = str_replace('、', '', $str);
        $str = str_replace('?', '', $str);
        $str = str_replace('？', '', $str);
        return trim($str);
    }
    /**
     * @author qiankun
     * @Fuction name ExportMemberAction
     * @description 导出错误会员excel
     */

    public function exportMemberAction()
    {
        try
        {
            $memberImportModel = new Statistics_MemberImportModel();
            $memberImportFileModel = new Statistics_MemberImportFileModel();
            //$limit = 1000;

            $where = array(
                'status' => 2,
                'seller_id' => $this->sellerId,
                'shop_id' => $this->shopId
            );
            if($importFile = $memberImportFileModel->find($where,array('id','create_time'),'id DESC'))
            {
                //最近一次导入失败的会员数据显示
                $where = array(
                    'seller_id' => $this->sellerId,
                    'shop_id' => $this->shopId,
                    'status' => 3,
                    'import_file_id' => $importFile['id'],
                );
                $field = array('phone', 'level', 'true_name', 'sex', 'birthday', 'balance', 'error_msg', 'card_no', 'create_time');
                $list = $memberImportModel->select($where, $field, $this->excelMaxExportLength);
                $str = "手机号,会员卡级别,余额,姓名,性别,生日,线下会员卡号（不可重复）,错误原因,导入时间\n";
                $str = iconv('utf-8', 'gb2312', $str);
                if(!empty($list))
                {
                    foreach($list as $k => $v)
                    {
                        $phone = iconv('utf-8', 'GBK//IGNORE', $v['phone']) . "\t\t";
                        $level = iconv('utf-8', 'GBK//IGNORE', $v['level']);
                        $balance = iconv('utf-8', 'GBK//IGNORE', number_format($v['balance'],2,".","")); //中文转码
                        $trueName = iconv('utf-8', 'GBK//IGNORE', $v['true_name'] ? $v['true_name']:'-');
                        $sex = iconv('utf-8', 'GBK//IGNORE', $v['sex'] == 1 ? '男' : ($v['sex'] == 2 ? '女' : ''));
                        $birthday = $v['birthday'] ? date('Y-m-d', $v['birthday']) . "\t\t" : '--';
                        $birthday = iconv('utf-8', 'GBK//IGNORE', $birthday);
                        $card_no = iconv('utf-8', 'GBK//IGNORE', $v['card_no'] . "\t\t");
                        $error_msg = iconv('utf-8', 'GBK//IGNORE', $v['error_msg'] ? $v['error_msg'] . "\t\t" : '');
                        $createTime = $v['create_time'] ? date('Y-m-d H:i:s', $v['create_time']) . "\t\t" : '--';
                        $createTime = iconv('utf-8', 'GBK//IGNORE', $createTime);
                        $str .= $phone . "," . $level . "," . $balance . "," . $trueName . "," . $sex . "," . $birthday . "," . $card_no . "," . $error_msg . "," . $createTime . "\n"; //用引文逗号分开
                    }
                }
                else
                {
                    throw new Exception('没有失败数据');
                }
                $filename = "导入失败" . date('md') . ".csv"; //设置文件名
                header("Content-type:text/csv");
                header("Content-Disposition:attachment;filename=" . urlencode($filename));
                header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
                header('Expires:0');
                header('Pragma:public');
                echo $str;
            }
            else
            {
                throw new Exception('未找到上一次导入的EXCEL');
            }
        }
        catch (Exception $e)
        {
            $this->showMessage(2, $e->getMessage(), $_SERVER['HTTP_REFERER'], "EXCEL失败会员导出", 3);
        }
    }

    /**
     * @author qiankun
     * @Fuction name shellCheckMemberAction
     * @description shell下检测会员,给测试人员使用
     */

    /**
    public function shellCheckMemberAction()
    {
        $memberImportModel = new Statistics_MemberImportModel();
        $memberImportFileModel = new Statistics_MemberImportFileModel();
        $file = $memberImportFileModel->find(array('status' => 1), array('id', 'file_id'), 'id ASC');
        if($file)
        {
            //差错处理机制，删除无内容的excel数据防止死循环
            $where = array('import_file_id' => $file['id']);
            if($id = $memberImportModel->find($where, array('id')))
            {
                $memberImportFileModel->deleteData(array('id' => $id));
            }
            //差错处理end
            $where = array(
                'status' => 1, 'import_file_id' => $file['id']
            );
            $limit = 500;//单次执行条数

            $list = $memberImportModel->select(
                $where, array('id', 'phone', 'level', 'balance', 'true_name', 'sex', 'birthday', 'card_no', 'seller_id', 'shop_id'), $limit
            );
            if(!empty($list))
            {
                foreach($list as $key => $value)
                {
                    $updateData = array();
                    $data = array(
                        'phone' => $value['phone'], 'shop_id' => $value['shop_id'], 'seller_id' => $value['seller_id'], 'level' => $value['level'], 'balance' => $value['balance'], 'true_name' => $value['true_name'], 'sex' => $value['sex'], 'birthday' => $value['birthday'], 'card_no' => $value['card_no'],
                    );
                    if(!in_array($data['sex'], array(0, 1, 2)))
                    {
                        $updateData['sex'] = 0;
                    }

                    if(!empty($data['card_no']))//判断卡号是否重复,重复设为空
                    {
                        $where = array(
                            'seller_id' => $value['seller_id'], 'shop_id' => $value['shop_id'], 'status' => array('in', '2,4'), 'card_no' => $data['card_no']
                        );
                        if($memberImportModel->count($where))
                        {
                            $updateData['card_no'] = '';
                        }
                    }
                    $isValidate = Member_ImportService::checkMemberImport($data);
                    if($isValidate['status'] == 0)
                    {
                        $updateData['status'] = 3;//不合格
                        $updateData['error_msg'] = $isValidate['msg'];
                    }
                    elseif($isValidate['status'] == 1)
                    {
                        $updateData['status'] = 2;//合格
                    }
                    $where = array('id' => $value['id']);
                    $memberImportModel->updateData($updateData, $where);//修改合格状态
                }
            }
            else//如果检查完
            {
                $data = array('status' => 2);
                $where = array(
                    'id' => $file['id'],
                );
                $memberImportFileModel->updateData($data, $where);//更新FILE表状态为已完成检查
            }

        }

    }
    **/
}